<template>
  <div class="app-container">
    <el-form ref="form" :model="form" label-width="120px">
      <el-form-item label="缴费内容">
        <el-input v-model="form.content" />
      </el-form-item>

      <el-form-item label="缴费金额">
        <el-input v-model="form.amount" />
      </el-form-item>

      <el-form-item label="缴费状态">
        <el-switch
          v-model="form.statusId"
          active-color="#13ce66"
          inactive-color="#ff4949"
          active-value="5"
          active-text="已缴费"
          inactive-value="6"
          inactive-text="待缴费"
        />
      </el-form-item>

      <el-form-item label="业主姓名">
        <el-input v-model="form.ownerName" />
      </el-form-item>

      <el-form-item label="业主电话">
        <el-input v-model="form.phone" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">确认提交</el-button>
        <el-button @click="onReset">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { addRow } from '@/api/payment'

export default {
  data() {
    return {
      form: {
        content: '',
        amount: '',
        statusId: '6', // 设置默认值为待缴费
        ownerName: '',
        phone: ''
      }
    }
  },
  methods: {
    validPayForm(form) {
      return form.content !== '' &&
             form.amount !== '' &&
             form.ownerName !== '' &&
             form.phone !== ''
    },
    onReset() {
      this.form = {
        content: '',
        amount: '',
        statusId: '6',
        ownerName: '',
        phone: ''
      }
      this.$message({
        message: '已重置',
        type: 'warning'
      })
    },
    onSubmit() {
      console.log('表单数据:', this.form)
      if (this.validPayForm(this.form)) {
        addRow(this.form)
          .then(response => {
            this.$message({
              message: '添加成功',
              type: 'success'
            })
          })
      } else {
        this.$message({
          message: '请填写完整信息',
          type: 'warning'
        })
      }
    }

  }
}
</script>

<style scoped>
.line{
  text-align: center;
}
</style>

